#ifndef __LIST_H
#define __LIST_H
#include"global.h"

//get the offset of member in the struct type
#define offset(struct_type,member) (uint32_t)(&((struct_type*)0)->member)
//通过ptr指针获取到包含它的结构体的指针
#define elem2entry(struct_type,struct_elem_name,ptr) (struct_type*)((uint32_t)ptr \
				-offset(struct_type,struct_elem_name))
typedef struct list_elem{
	struct list_elem* prev;
	struct list_elem* next;
}list_elem;

typedef struct{
	list_elem head;
	list_elem tail;
}list;

typedef bool (* list_call_back)(list_elem*,int);

void list_init(list* plist);
void list_insert_before(list_elem* before,list_elem* pelem);
//add the elem to the tail
void list_append(list* plist,list_elem* pelem);
void list_remove(list_elem* pelem);
//add the elem at the head
void list_push(list* plist,list_elem* pelem);
list_elem* list_pop(list* plist);
bool list_empty(list* plist);
uint32_t list_len(list* plist);
list_elem* list_traversal(list* plist,list_call_back call_back,int arg);
int elem_find(list* plist,list_elem* pelem);
#endif
